<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Calculator() {
        let methods = {};
        this.calculate = function (exp) {
          const [a, opt, b] = exp.split(" ");
          return methods[opt](+a, +b);
        };

        this.addMethod = function (opt, cb) {
          methods[opt] = cb;
        };
      }
      let calc = new Calculator();
      
      calc.addMethod("+", (a, b) => a + b);
      calc.addMethod("-", (a, b) => a - b);
      calc.addMethod("*", (a, b) => a * b);
      calc.addMethod("/", (a, b) => a / b);
      calc.addMethod("**", (a, b) => a ** b);
      calc.addMethod("++", (a, b) => {
        let r = 0;
        for (let i = 0; i < +b; i++) {
          r += +a;
        }
        return r;
      });
      calc.addMethod("--", function (a, b) {
        for (let i = 0; i < b; i++) {
          a -= b;
        }
        return a;
      });

      console.log(calc.calculate("3 + 8")); //10
      console.log(calc.calculate("3 * 8")); //11
      console.log(calc.calculate("2 ** 3")); //8
      console.log(calc.calculate("2 ++ 3")); //8
      console.log(calc.calculate("10 -- 3")); //8
    </script>
  </body>
</html>
